/*
 * AY 2014/15 Semester 1 IS2103 Assignment Part2
 * Matric. No.:    A0102330H
 * Name:           Cui Lin
 */
package ejb;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author cuilin
 */
@Entity
public class ModuleEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String moduleCode;
    private String moduleTitle;
    private String t;
    private String venue;
    @ManyToOne(cascade = {CascadeType.ALL})
    private LecturerEntity lecturer;
    @OneToOne(cascade = {CascadeType.PERSIST})
    private SynopsisEntity synopsis;
    @ManyToMany
    @JoinTable(name = "STUDENTBI_MODULEBI")
    private Set<StudentEntity> students;
    @OneToMany(cascade = {CascadeType.ALL})
    private Set<TutorialEntity> tutorials;

    public ModuleEntity() {
    }

    public void create(String moduleCode, String moduleTitle, String t, String venue) {
        this.moduleCode = moduleCode;
        this.moduleTitle = moduleTitle;
        this.t = t;
        this.venue = venue;
    }
    
    public void addStudentEntity(StudentEntity student){
        if(null == students || students.isEmpty()){
            students = new HashSet<StudentEntity>();
        }
        students.add(student);
    }
    
    public void addTutorialEntity(TutorialEntity tutorial){
        if(null == tutorials || tutorials.isEmpty()){
            tutorials = new HashSet<TutorialEntity>();
        }
        tutorials.add(tutorial);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getModuleCode() {
        return moduleCode;
    }

    public void setModuleCode(String moduleCode) {
        this.moduleCode = moduleCode;
    }

    public String getModuleTitle() {
        return moduleTitle;
    }

    public void setModuleTitle(String moduleTitle) {
        this.moduleTitle = moduleTitle;
    }

    public String getT() {
        return t;
    }

    public void setT(String t) {
        this.t = t;
    }

    public String getVenue() {
        return venue;
    }

    public void setVenue(String venue) {
        this.venue = venue;
    }

    public LecturerEntity getLecturer() {
        return lecturer;
    }

    public void setLecturer(LecturerEntity lecturer) {
        this.lecturer = lecturer;
    }

    public SynopsisEntity getSynopsis() {
        return synopsis;
    }

    public void setSynopsis(SynopsisEntity synopsis) {
        this.synopsis = synopsis;
    }

    public Set<StudentEntity> getStudents() {
        return students;
    }

    public void setStudents(Set<StudentEntity> students) {
        this.students = students;
    }

    public Set<TutorialEntity> getTutorials() {
        return tutorials;
    }

    public void setTutorials(Set<TutorialEntity> tutorials) {
        this.tutorials = tutorials;
    }
}
